package com.qf.main.pharmacy.controller;

import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.ResponseResult;
import com.qf.main.pharmacy.common.qo.ShopQo;
import com.qf.main.pharmacy.common.vo.PharmacyVO;
import com.qf.main.pharmacy.common.vo.ShopVo;
import com.qf.main.pharmacy.mapper.ShopMapper;
import com.qf.main.pharmacy.service.ShopService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-02-19-10:46
 * @Description:
 */
@RestController
@RequestMapping("/shop")
@CrossOrigin
@Api(tags = "店铺")
public class ShopController {
    @Resource
    private ShopService shopService;

    @PostMapping("/save")
    public ResponseResult<Integer> saveShop(@RequestBody ShopQo shopQo){
        System.out.println(shopQo);
        return ResponseResult.success(shopService.saveShop(shopQo));
    }

    @DeleteMapping("/edit")
    public ResponseResult<Integer> editShop(@RequestParam("shopNo") String shopNo){
        return ResponseResult.success(shopService.removeShop(shopNo));
    }
    @PutMapping("/erase")
    public ResponseResult<Integer> eraseShop(@RequestBody ShopQo shopQo){
        return ResponseResult.success(shopService.modifyShop(shopQo));
    }
    @GetMapping("/get")
    public ResponseResult<ShopVo> getShop(@RequestParam("shopNo") String shopNo){
        System.out.println(shopNo);
        return ResponseResult.success(shopService.getShop(shopNo));
    }
    @GetMapping("/mall/list")
    public ResponseResult<PageInfo<PharmacyVO>> listShopMall(@RequestParam(value = "pageNum" ,required = false) Integer pageNum,
                                                                @RequestParam(value = "pageSize" ,required = false) Integer pageSize,
                                                                @RequestParam("shopNo") String shopNo){
        return ResponseResult.success(shopService.mallListByShopNo(pageNum,pageSize,shopNo));
    }
    @PutMapping("/erase/status/open")
    public ResponseResult<Integer> openShop(@RequestParam("shopNo") String shopNo){

        return ResponseResult.success(shopService.status(shopNo,1));
    }
    @PutMapping("/erase/status/close")
    public ResponseResult<Integer> closeShop(@RequestParam("shopNo") String shopNo){

        return ResponseResult.success(shopService.status(shopNo,0));
    }

}
